<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <base href="<?= base_url() ?>"/>
        <title>乐天！ &raquo; 首页</title>
        <meta name="generator" content="Order 1.0" /> 
        <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
        <link rel="stylesheet" href="css/style.css" type="text/css" />
        <link rel="stylesheet" href="css/uploadify.css" type="text/css" />
        <link rel="stylesheet" href="jquery-ui/css/ui-lightness/jquery-ui-1.9.0.custom.min.css" />
        <script src="jquery-ui/js/jquery-1.8.2.js" type="text/javascript" charset="utf-8"></script>
        <script src="jquery-ui/js/jquery-ui-1.9.0.custom.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.uploadify.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
        <script>
            $(function() {        
                var uid = -1;//用户的编号
                $(".link_mod").click(function(e){
                    uid = e.target.parentElement.parentElement.firstChild.innerHTML;
                    var data = "uid="+uid;
                    var url="<?php echo site_url('admin/user_detail'); ?>";
                    $.post(url,data,function(response){
                        var obj =eval('(' + response + ')');; //由JSON字符串转换为JSON对象
                        $("#uname").val(obj.uname);
                        $("#upass").val(obj.upass);
                        if(obj.p1!='0') $("#p1").attr('checked',true);
                        if(obj.p2!='0') $("#p2").attr('checked',true);
                        if(obj.p3!='0') $("#p3").attr('checked',true);
                        if(obj.p4!='0') $("#p4").attr('checked',true);
                        if(obj.p5!='0') $("#p5").attr('checked',true);
                        if(obj.p6!='0') $("#p6").attr('checked',true);      
                    });
                    
                    $("#uname").attr('disabled', true);
                    $("#user_form").show();
                    $("#bgDiv").show();
                    return false;
                });
                $(".link_add").click(function(){
                    uid = -1;
                    $("#user_form input[type=text]").val("");
                    $("#user_form :checkbox").attr('checked',false);
                    $("#user_form").show();
                    $("#bgDiv").show();
                    return false;
                });
                $(".link_yes").click(function(e){return false;});
                $(".link_no").click(function(e){return false;});
                $(".link_del").click(function(e){
                    if(confirm("确定删除？"))
                    {
                        var uid = e.target.parentElement.parentElement.firstChild.innerHTML;
                        var data = "uid="+uid;
                        var url="<?php echo site_url('admin/user_delete'); ?>";
                        $.post(url,data,function(response){
                            if(response == "success"){
                                alert('删除用户成功');
                                window.location.reload(); 
                            }else {
                                alert('删除用户失败');
                            }
                        });
                        return false;
                    }
                    return false;
                });
                $(".link_close").click(function(){
                    $("#uname").attr('disabled', false);
                    $("#user_form input[type=text]").val("");
                    $("#user_form :checkbox").attr('checked',false);
                    $("#user_form").hide();
                    $("#bgDiv").hide();
                    return false;
                });
                $("#user_cancle").click(function(){
                    $("#uname").attr('disabled', false);
                    $("#user_form input[type=text]").val("");
                    $("#user_form :checkbox").attr('checked',false);
                    $("#user_form").hide();
                    $("#bgDiv").hide();
                });
                
                $("#user_form_test").validationEngine({
                    onValidationComplete: function(form, status){
                        if(status==true )     
                        {  
                            if(uid==-1){
                                var data = $("#user_form_test").serialize();
                                var url=$("#user_form_test")[0].action;
                                $.post(url,data,function(response){
                                    if(response == "success"){
                                        alert('添加用户成功');
                                        window.location.reload(); 
                                    }else if(response == "error_3"){
                                        alert('该用户已被注册');
                                    }else {
                                        alert('添加用户失败');
                                    }
                                });
                            }else{
                                var data = "uid="+uid+'&';
                                var data = data+$("#user_form_test").serialize();
                                //alert(data);
                                var url="<?php echo site_url('admin/user_modify'); ?>";
                               // alert(url);
                                $.post(url,data,function(response){
                                    //alert(response);
                                    if(response == "success"){
                                        alert('修改成功');
                                        window.location.reload(); 
                                    }else{
                                        alert('修改失败');
                                    }
                                });
                            }
                        } 
                        return false;
                    }
                });
            });    
        </script>
        <style>
            .search_bnt {
                height: 32px;
                font-weight:bold;
                font-size:13px;
                width: 100%;
                background: #7FA448;
                margin: 0;
                border: none;
                cursor: pointer;
                color: white;
            }
            .search_bnt:hover{
                background: #8cb352;
            }
            #user_form{
                background:white;width:300px;padding:20px 20px 10px 20px;margin:0px;border: 5px solid #CCC;
                position: fixed;
                z-index:9999;
                position:absolute;   
                top:50%;
                left:50%;
                margin:-210px 0 0 -150px;
                display: none;
            }
            .hide{
                display: none;
            }
            th,td{
                padding:3px;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="header">
                <div id="header-inner">
                    <h1><span><a href="#">乐天！</a></span></h1>
                    <h2>订单管理系统</h2>
                    <div class="clear"></div>
                    <ul class="sw_menu">
                        <li><a href=<?php echo site_url('login') ?> >首页</a></li>
                        <li><a href=<?php echo site_url('order') ?> >管理</a></li>
                        <li><a href=# >筛选</a></li>
                        <li><a href=<?php echo site_url('admin') ?> class="sw_menu_current" >后台</a></li>
                    </ul>
                </div>
            </div>
            <div id="sidebar">
                <div id="sidebar-inner">
                    <ul>
                        <li class="select">>
                            <a href="<?php echo site_url("admin") ?>">用户管理</a>
                        </li>
                        <div class="clear"></div>
                    </ul>
                </div>
            </div>

            <div id="bgDiv"></div>
            <div id="content-wrapper">
                <div style=" display: none;line-height:40px;height: 40px;margin-left:250px;color:white; width:200px;font-size:16px;background:#cc6600;text-align: center;" id='showup'>正在提交订单</div>
                <div id="content">
                    <h3 id="comments-title">       <em>用户列表</em>       </h3>
                    <div class="comment-form">

                        <p>用户信息</p>
                        <table id ="user_table">
                            <tr>
                                <th class="hide">用户id</th>
                                <th>用户名</th>
                                <th>密码</th>
                                <th>新建订单处理</th>
                                <th>待付款订单处理</th>
                                <th>待采购订单处理</th>
                                <th>待发货订单处理</th>
                                <th>已发货订单处理</th>
                                <th>后台管理</th>
                                <th style="width:100px;">修改|删除 </th>        
                            </tr>
                            <?php
                            foreach ($userinfo as $user) {
                                echo "<tr>";
                                echo "<td class='hide'>" . $user['uid'] . "</td>";
                                echo "<td>" . $user['uname'] . "</td>";
                                echo "<td>" . $user['upass'] . "</td>";
                                echo "<td>";
                                if ($user['p1'] == '0')
                                    echo "<a href='#' class='link_no'></a>" . "</td>";
                                else
                                    echo "<a href='#' class='link_yes'></a>" . "</td>";
                                echo "<td>";
                                if ($user['p2'] == '0')
                                    echo "<a href='#' class='link_no'></a>" . "</td>";
                                else
                                    echo "<a href='#' class='link_yes'></a>" . "</td>";
                                echo "<td>";
                                if ($user['p3'] == '0')
                                    echo "<a href='#' class='link_no'></a>" . "</td>";
                                else
                                    echo "<a href='#' class='link_yes'></a>" . "</td>";
                                echo "<td>";
                                if ($user['p4'] == '0')
                                    echo "<a href='#' class='link_no'></a>" . "</td>";
                                else
                                    echo "<a href='#' class='link_yes'></a>" . "</td>";
                                echo "<td>";
                                if ($user['p5'] == '0')
                                    echo "<a href='#' class='link_no'></a>" . "</td>";
                                else
                                    echo "<a href='#' class='link_yes'></a>" . "</td>";
                                echo "<td>";
                                if ($user['p6'] == '0')
                                    echo "<a href='#' class='link_no'></a>" . "</td>";
                                else
                                    echo "<a href='#' class='link_yes'></a>" . "</td>";
                                echo "<td><a href='#' class='link_mod'></a>|" . "<a href='#' class='link_del'></a></td>";
                                echo "</tr>";
                            }
                            ?>
                        </table>
                        <a href="" class="link_add" id ="add_user" >添加用户</a>
                    </div>       
                    <div id="user_form">
                        <form action=<?php echo site_url("admin/user_create"); ?> method="post" id="user_form_test">
                            <div style="border-bottom: 1px solid #EAEAEA;height: 40px;line-height: 40px;color: #333;font-size: 16px;margin-bottom: 20px;">
                                <div style="float:left;display:inline;">用户信息</div>
                                <div> <a style="float:right;line-height:20px;padding:10px;" href="#" class="link_close"></a></div>
                            </div>
                            <div class="clear"></div>
                            <div style="margin: 10px 0px;">
                                <label>用户名</label>
                                <input type="text" name='uname' id="uname" class="validate[required]" value="" size="20" />
                            </div>
                            <div style="margin: 10px 0px;">
                                <label>密&nbsp&nbsp码&nbsp</label>
                                <input type="text" name='upass' id="upass" class="validate[required]" value="" size="20" />
                            </div>
                            <hr/>
                            <div style="margin: 10px 0px;">
                                <input type="checkbox" name='p1' id="p1"/>
                                <label>新建订单处理</label>
                            </div>
                            <div style="margin: 10px 0px;">
                                <input type="checkbox" name="p2" id="p2"/>
                                <label>待付款订单处理</label>
                            </div>
                            <div style="margin: 10px 0px;">
                                <input type="checkbox" name="p3" id="p3"/>
                                <label>待采购订单处理</label>
                            </div>
                            <div style="margin: 10px 0px;">
                                <input type="checkbox"  name="p4" id="p4"/>
                                <label>待发货订单处理</label>
                            </div>
                            <div style="margin: 10px 0px;">
                                <input type="checkbox"  name="p5" id="p5"/>
                                <label>已发货订单处理</label>
                            </div>
                            <div style="margin: 10px 0px;">
                                <input type="checkbox"  name="p6" id="p6"/>
                                <label>后台管理</label>
                            </div>
                            <p>
                                <div style="padding-top: 10px;">
                                    <input type="submit" class="search_bnt" id ="user_comfirm" style="width:80px;margin-left:40px" value="确认"/>
                                    <input type="button" class="search_bnt" id ="user_cancle" style="width:80px;margin-left:40px"value="取消"/>
                                </div> 
                            </p> 
                        </form>
                    </div>  

                </div>    
            </div>
            <div class="clear"></div>
            <div id="footer">
                <hr />
                <ul>
                    <li>
                        Powered by <a href=#>Swan 1.3.0</a>
                    </li>
                </ul>
            </div>
        </div>
    </body>
</html>